import { http } from '@/api/http'
import { httpErrorHandle } from '@/utils'
import { ContentTypeEnum, RequestHttpEnum } from '@/enums/httpEnum'

// * 列表
export const componentListApi = async () => {
    try {
      const res = await http(RequestHttpEnum.GET)(`component/list`)
      return res
    } catch {
      httpErrorHandle()
    }
}

// * 新增
export const createComponentApi = async (data: object) => {
    try {
      const res = await http(RequestHttpEnum.POST)(`component/add`, data)
      return res
    } catch {
      httpErrorHandle()
    }
  }
  
  // * 获取
  export const fetchComponentApi = async (id: string) => {
    try {
      const res = await http(RequestHttpEnum.GET)(`component/get?id=${id}`)
      return res
    } catch {
      httpErrorHandle()
    }
  }
  
  // * 更新
  export const saveComponentApi = async (data: object) => {
    try {
      const res = await http(RequestHttpEnum.POST)(
        `component/update`,
        data
      )
      return res
    } catch {
      httpErrorHandle()
    }
  }
  
  // * 删除项目
  export const deleteComponentApi = async (id: string) => {
    try {
      const res = await http(RequestHttpEnum.GET)(`component/delete?id=${id}`)
      return res
    } catch {
      httpErrorHandle()
    }
  }